﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SIMc
{
    public partial class SettingsForm : Form
    {
        MainForm form1;
        public SettingsForm(MainForm form)
        {
            InitializeComponent();
            this.form1 = form;
        }

        private void B_Apply_Click(object sender, EventArgs e)
        {

        }

        private void TB_registrar_TextChanged(object sender, EventArgs e)
        {

        }

        private void B_acc1_OK_Click(object sender, EventArgs e)
        {
            //acc1
            form1.profil.accounts[0].uri = TB_acc1_acc.Text;
            form1.profil.accounts[0].use = CB_acc1_use.Checked;
            form1.profil.accounts[0].password = TB_acc1_pass.Text;
            form1.profil.accounts[0].proxy = TB_acc1_proxy.Text;
            form1.profil.accounts[0].realm = TB_acc1_realm.Text;
            form1.profil.accounts[0].registrar = TB_acc1_registrar.Text;

            form1.xmlProfiles.updateProfile(form1.profil);
            MessageBox.Show("Changes will take effect after next successful registration");
        }

        private void B_acc2_OK_Click(object sender, EventArgs e)
        {
            //acc2
            form1.profil.accounts[1].uri = TB_acc2_acc.Text;
            form1.profil.accounts[1].use = CB_acc2_use.Checked;
            form1.profil.accounts[1].password = TB_acc2_pass.Text;
            form1.profil.accounts[1].proxy = TB_acc2_proxy.Text;
            form1.profil.accounts[1].realm = TB_acc2_realm.Text;
            form1.profil.accounts[1].registrar = TB_acc2_registrar.Text;

            form1.xmlProfiles.updateProfile(form1.profil);
            MessageBox.Show("Changes will take effect after next successful registration");
        }

        private void B_acc3_OK_Click(object sender, EventArgs e)
        {
            //acc3
            form1.profil.accounts[2].uri = TB_acc3_acc.Text;
            form1.profil.accounts[2].use = CB_acc3_use.Checked;
            form1.profil.accounts[2].password = TB_acc3_pass.Text;
            form1.profil.accounts[2].proxy = TB_acc3_proxy.Text;
            form1.profil.accounts[2].realm = TB_acc3_realm.Text;
            form1.profil.accounts[2].registrar = TB_acc3_registrar.Text;

            form1.xmlProfiles.updateProfile(form1.profil);
            MessageBox.Show("Changes will take effect after next successful registration");
        }

        private void B_acc4_OK_Click(object sender, EventArgs e)
        {
            //acc4
            form1.profil.accounts[3].uri = TB_acc4_acc.Text;
            form1.profil.accounts[3].use = CB_acc4_use.Checked;
            form1.profil.accounts[3].password = TB_acc4_pass.Text;
            form1.profil.accounts[3].proxy = TB_acc4_proxy.Text;
            form1.profil.accounts[3].realm = TB_acc4_realm.Text;
            form1.profil.accounts[3].registrar = TB_acc4_registrar.Text;

            form1.xmlProfiles.updateProfile(form1.profil);
            MessageBox.Show("Changes will take effect after next successful registration");
        }

        /// <summary>
        /// posunutie a zmena velkosti komponent ked zapnem klavesnicu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InputPanel1_EnabledChanged(object sender, EventArgs e)
        {
            //SuspendLayout();
            if (inputPanel1.Enabled)
            {
                TC_settings.Height = TC_settings.Height - inputPanel1.Bounds.Height;
                panel1.Height =panel1.Height - inputPanel1.Bounds.Height;
            }
            else
            {
                TC_settings.Height = TC_settings.Height + inputPanel1.Bounds.Height;
                panel1.Height = panel1.Height = panel1.Height + inputPanel1.Bounds.Height;
            }
        }

        private void B_call_OK_Click(object sender, EventArgs e)
        {
            form1.config.codec = CB_codec.SelectedItem.ToString();
            form1.config.VAD = CB_VAD.Checked;
            form1.config.ec_tail = int.Parse(TB_ecTail.Text);
            form1.config.clock_rate = int.Parse(TB_clockRate.Text);
            form1.config.quality = CB_quality.SelectedIndex + 1;
            form1.config.ptime = int.Parse(TB_ptime.Text);

            form1.xmlConfig.updateProfile(form1.config, form1.profil.ID);
            MessageBox.Show("Changes will take effect after next successful registration");
        }

        private void B_general_OK_Click(object sender, EventArgs e)
        {
            //form1.config.autologin = CB_autologin.Checked;
            form1.config.port = int.Parse(TB_port.Text);
            form1.config.expire = int.Parse(TB_expire.Text);
            form1.config.xcap = TB_xcap.Text;

            form1.xmlConfig.updateProfile(form1.config, form1.profil.ID);
            MessageBox.Show("Changes will take effect after next successful registration");
        }

        private void B_stun_OK_Click(object sender, EventArgs e)
        {
            form1.config.stun = TB_stun.Text;
            form1.config.useStun = CB_useSTUN.Checked;
            form1.xmlConfig.updateProfile(form1.config, form1.profil.ID);
            MessageBox.Show("Changes will take effect after next successful registration");
        }
    }
}